%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
%clear all
% parametor of index J
K=40; N=4; RNK=[4,4,ones(1,38)];%,1,1,1,1,1,1,1,1,1,1]; %control index
%K=20; N=4; RNK=[4,4,ones(1,18)];
%K=10; N=4; RNK=[4,4,ones(1, 8)];
%K= 5; N=4; RNK=[4,4,ones(1, 3)];
% K=3; N=4; RNK=[4,2,1];
% construct JNKR
JNKR = index(K,N,RNK);
fname='indexJNKR';
save(fname,'JNKR');
% time 
t = 1;
% construct orthogoal basis in L2[0,t]
orthbasis(t);
% interest
R=@(s) cos(exp(-s));
R=@(s) 0+s-s;
% volatility
sig=@(s) 1+s-s;
%sig=@(s) sin(exp(-s));
% sig=@(s) sin(10*exp(s));
% sig=@(s) sin(10*s);
% sig=@(s) 1+s-s;
% sig=@(s) exp(s);
% initial condition
y0=zeros(size(JNKR,1),1);
yic=1;
y0(1)=yic;
% solver
tspan = linspace(0,t,100);
options = odeset('AbsTol',1e-12,'RelTol',1e-6);
[time,y] = ode45(@randomforce,tspan,y0,[],R,sig);
% error
meanerr(time',y,R,sig,y0)
%varerr(time',y,R,sig,y0)


